<template>
	<uni-card :title="topTitle">
		<uni-row>
			<uni-col :span="8" >
				<view style=" display: flex; justify-content: center;  align-items: center; font-size: 15px; font-weight: 400;" @click="toDormitoryAttenceDetail('dormitory')">宿舍未打卡</view>
			</uni-col>
			<uni-col :span="8" >
				<view style=" display: flex; justify-content: center;  align-items: center; font-size: 15px; font-weight: 400;" @click="toDormitoryAttenceDetail('weekend')">周末未打卡</view>
			</uni-col>
			<uni-col :span="8">
				<view  style=" display: flex; justify-content: center;  align-items: center; font-size: 15px; font-weight: 400;" @click="toRetentionCount()">滞留人数</view>
			</uni-col>
		</uni-row>
		<uni-row>
			<uni-col :span="8"  >
					<view style="font-weight: 700; font-size: 15px; display: flex; justify-content: center;  align-items: center;" @click="toDormitoryAttenceDetail('dormitory')">{{boardData.dormitorySummary}}</view>
			</uni-col>
			<uni-col :span="8" >
					<view style="font-weight: 700; font-size: 15px; display: flex; justify-content: center;  align-items: center;" @click="toDormitoryAttenceDetail('weekend')">{{boardData.weekendSummary}}</view>
			</uni-col>
			<uni-col :span="8" >
				<view style="font-weight: 700; font-size: 15px; display: flex; justify-content: center;  align-items: center;" @click="toRetentionCount()">{{boardData.retentionSummary}}</view>
			</uni-col>
		</uni-row>
		<uni-row>
			<uni-col :span="8">
				<view  @click="toMorningExercisesCount()" style=" display: flex; justify-content: center;  align-items: center; font-size: 15px; font-weight: 400;">早操未到</view>
			</uni-col>
			<uni-col :span="8">
				<view  style=" display: flex; justify-content: center;  align-items: center; font-size: 15px; font-weight: 400;" @click="toViolationPatrol()">白天违纪</view>
			</uni-col>
			<uni-col :span="8" >
				<view style=" display: flex; justify-content: center;  align-items: center; font-size: 15px; font-weight: 400;" @click="toDormitoryViolations()">宿舍违纪</view>
			</uni-col>
		</uni-row>
		<uni-row>
			<uni-col :span="8" >
				<view  style="font-weight: 700; font-size: 15px; display: flex; justify-content: center;  align-items: center;" @click="toMorningExercisesCount()">{{boardData.morningSummary}}</view>
			</uni-col>
			<uni-col :span="8" >
				<view  style="font-weight: 700; font-size: 15px; display: flex; justify-content: center;  align-items: center;" @click="toViolationPatrol()">{{boardData.dayViolationSummary}}</view>
			</uni-col>
			<uni-col :span="8">
				<view  style="font-weight: 700; font-size: 15px; display: flex; justify-content: center;  align-items: center;" @click="toDormitoryViolations()">{{boardData.nightViolationSummary}}</view>
			</uni-col>
		</uni-row>
	</uni-card>
</template>

<script>
	import manageTeacher from '@/api/modules/managementTeacher.js'
	export default {
		name : "deptManagerPanel",
		props: {
			topTitle: String,
			type: String
		},
		data() {
			return {
				boardData: {
					dayViolationSummary: 0,
					dormitorySummary: 0,
					morningSummary: 0,
					nightViolationSummary: 0,
					retentionSummary: 0,
					weekendSummary: 0
				},
				roleName: '',
				userName: '',
				userId: '',
				operateType: '',
				datetime: '',
			}
		},
		created() {
			this.userId = uni.getStorageSync("loginId");
			this.roleName = uni.getStorageInfoSync("userRole")
			this.getBoardData();
		},
		methods: {
			getLocalDateString(nowDate) {
			    const year = nowDate.getFullYear();
			    const month = (nowDate.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始，需要加1并补零
			    const day = nowDate.getDate().toString().padStart(2, '0'); // 补零
			    const localDateString = year + '-' + month + '-' + day;
			    return localDateString;
			},
			toRetentionCount() {
				const today = new Date();
				const yesterday = new Date(today);
				if(this.type == 'yesterday'){
					console.log("is yesterday")
					yesterday.setDate(yesterday.getDate() - 1);
				}
				this.datetime = this.getLocalDateString(yesterday);
				uni.navigateTo({
					url:`/pages_duty/classTeacher/retention/retentionCount?datetime=${this.datetime}`
				})
			},
			toMorningExercisesCount() {
				const today = new Date();
				  const yesterday = new Date(today);
				  if(this.type == 'yesterday'){
						yesterday.setDate(yesterday.getDate() - 1);
				  }
				this.datetime = this.getLocalDateString(yesterday);
				uni.navigateTo({
					url:`/pages_duty/classTeacher/morningExercises/morningExercisesCount?datetime=${this.datetime}`
				})
			},
			toDormitoryAttenceDetail(operateType) {
				this.operateType = operateType
				  const today = new Date();
				  const yesterday = new Date(today);
				  if(this.type == 'yesterday'){
						yesterday.setDate(yesterday.getDate() - 1);
				  }
				this.datetime = this.getLocalDateString(yesterday);
				console.log(this.datetime)
				uni.navigateTo({
					url:`/pages_duty/classTeacher/dormitoryAttence/dormitoryAttenceSummary?userId=${this.userId}&dateTime=${this.datetime}&operateType=${this.operateType}`
				})
			},
			toDormitoryViolations() {
				const today = new Date();
				  const yesterday = new Date(today);
				  if(this.type == 'yesterday'){
						yesterday.setDate(yesterday.getDate() - 1);
				  }
				this.datetime = this.getLocalDateString(yesterday);
				uni.navigateTo({
					url: `/pages_duty/dormitoryTeacher/patrol/patrolStatistics?dateTime=${this.datetime}`
				});
			},
			toViolationPatrol() {
				const today = new Date();
				  const yesterday = new Date(today);
				  if(this.type == 'yesterday'){
						yesterday.setDate(yesterday.getDate() - 1);
				  }
				this.datetime = this.getLocalDateString(yesterday);
				uni.navigateTo({
					url: `/pages_duty/securityStaff/violationPatrolStatistics?dateTime=${this.datetime}`
				});
			},
			getBoardData() {
				manageTeacher.getBoardData(this.userId, this.type).then(res => {
					this.boardData = res.data	
				}).catch(e => {
					
				})
			}
		}
	}
	
</script>

<style>
</style>